package service

import (
	"gin/common"
	"gin/common/constant"
	"gin/common/db/config"
	util2 "gin/common/util"
	"gin/system/entity"
	"github.com/gin-gonic/gin"
)

/**
*部门管理
2024-11-14 10:20
wangwei
*/
func GetDeptList(c *gin.Context) {
	resultList := make([]*entity.SysDept, 0)

	//TODO 部门管理查询待补充
	deptErr := config.GormDb.Model(&entity.SysDept{}).Table("sys_dept").
		Select("dept_id", "parent_id", "ancestors", "dept_name", "order_num", "leader", "phone", "email",
			"status", "del_flag", "create_by", "create_time ").
		Where("LOWER(1) = LOWER(?)", 1).Scan(&resultList).Error
	if deptErr != nil {
		common.ReturnError(c, constant.ERRORCODE(), constant.ERRORMSG()+",错误详细信息为： "+util2.MapToJson(deptErr), "", int64(len("")))
		panic("")
	}
	common.ReturnSucess(c, constant.SUCCESSCODE(), constant.SUCCESSMSG(), resultList, int64(len(resultList)))
}

/****
用户部门菜单树
获取单位下拉树列表A
2024-11-19 09:14
wangwei
***/
func GetTreeselect(c *gin.Context) {
	resultList := make([]*entity.SysDept, 0)
	deptErr := config.GormDb.Model(&entity.SysDept{}).Table("sys_dept").
		Select("dept_id", "parent_id", "ancestors", "dept_name", "order_num", "leader", "phone", "email",
			"status", "del_flag", "create_by", "create_time ").
		Where("LOWER(del_flag) = LOWER(?)", "0").Scan(&resultList).Error
	if deptErr != nil {
		common.ReturnError(c, constant.ERRORCODE(), constant.ERRORMSG()+",错误详细信息为： "+util2.MapToJson(deptErr), "", int64(len("")))
		panic("")
		common.ReturnSucess(c, constant.SUCCESSCODE(), constant.SUCCESSMSG(), resultList, int64(len(resultList)))
	}
}
